// pages/new-pages/filter-label/filter-label.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        treeList:[],
        navIndex:0,
        firstIndex:0
    },
    clickItem(e){
        let index = e.currentTarget.dataset.index;
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];  //上一个页面
        let wayList = this.data.jobWayList;
        let id = wayList[index].Id;
        
        let flag = this.data.flag;
        wx.navigateBack({
            delta: 1,
            success: function (res) {
                let data = prevPage.getSelectFilterData();
                data.positionId = id;
                prevPage.setFromIndexActive(index);
                if (flag && flag == 1){
                    prevPage.getQueryResumes(data , false);
                }else{
                    prevPage.getQueryJobs(data, false);
                }
            }
        });
    },
    getPositionData() {
        let that = this;
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        wx.request({
            url: app.globalData.serverAddress.getHomePositionData,
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            success: function (res) {
                console.log("getHomePositionData response", res);
                if (res.statusCode == 200 && res.data.CodeStatus == 20000) {
                    let positionData = res.data.BodyContent;
                    that.setData({
                        treeList: positionData
                    })
                }
            },
            fail: function (res) {
                console.log("getHomePositionData fail", res);
            },
            complete:function(res){wx.hideLoading()}
        });
    },
    //主列表点击事件
    clickNav(e){
        let index = e.detail.index;
        this.setData({navIndex:index})
        if(index == 0){
            this.setPageResult('');
        }
    },
    //侧滑栏一级列表点击事件
    clickFirstItem(e){
        let index = e.detail.index;
        this.setData({ firstIndex: index })
        let firstId = this.data.treeList[this.data.navIndex].SubLevelList[index].Id
        if (index == 0) {
            this.setPageResult(firstId);
        }
        console.log(firstId)
    },
    //侧滑栏二级列表点击事件
    clickSecondItem(e){
        let index = e.detail.index;
        let secondeId = this.data.treeList[this.data.navIndex].SubLevelList[this.data.firstIndex].SubLevelList[index].Id
        console.log(secondeId)
        this.setPageResult(secondeId);
    },
    setPageResult(id){
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];  //上一个页面
        let index = this.data.navIndex
        wx.navigateBack({
            delta: 1,
            success: function (res) {
                let data = prevPage.getSelectFilterData();
                data.positionId = id;
                prevPage.setFromIndexActive(index);
                prevPage.getQueryResumes(data, false);
            }
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //因为要传的对象太庞大，可能导致该页面进入有几秒卡死
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        this.setData({
            treeList: prevPage.data.positionFilter
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})